package com.zee.solr;

import java.util.Arrays;
import java.util.Collection;
import java.util.Map;

import org.apache.lucene.analysis.Tokenizer;
import org.apache.lucene.analysis.core.UnicodeWhitespaceTokenizer;
import org.apache.lucene.analysis.util.TokenizerFactory;
import org.apache.lucene.util.AttributeFactory;

/**
 * @author chenzhiqiang
 * @date 2018-03-26 14:54:45
 */

public class MyVerticalLineTokenizerFactory extends TokenizerFactory {

	public static final String RULE_JAVA = "java";
	public static final String RULE_UNICODE = "unicode";
	private static final Collection<String> RULE_NAMES = Arrays.asList(RULE_JAVA, RULE_UNICODE);

	private final String rule;

	/** Creates a new MyVerticalLineTokenizerFactory */
	public MyVerticalLineTokenizerFactory(Map<String, String> args) {
		super(args);

		rule = get(args, "rule", RULE_NAMES, RULE_JAVA);

		if (!args.isEmpty()) {
			throw new IllegalArgumentException("Unknown parameters: " + args);
		}
	}

	/**
	 * 区间：192.168.10.2~192.168.10.5 搜索 192.168.10.3，把区间数据也拿出来
	 *
	 * 
	 */

	@Override
	public Tokenizer create(AttributeFactory factory) {
		switch (rule) {
		case RULE_JAVA:
			return new MyVerticalLineTokenizer(factory);
		case RULE_UNICODE:
			return new UnicodeWhitespaceTokenizer(factory);
		default:
			throw new AssertionError();
		}
	}

}
